package com.didispace.chapter56.utils;

import lombok.Data;

@Data
public class RestResult<T> {

    private Integer code;

    private String message;

    private T data;

    public RestResult() {
    }

    public RestResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> RestResult<T> success(T data) {
        return new RestResult<T>(200, "返回数据成功", data);
    }

    /**
     * 失败返回结果
     *
     * @param message 消息
     */
    public static <T> RestResult<T> failed(String message) {
        return new RestResult<T>(500, message, null);
    }
}
